package com.avo.ramcache.persist;

import com.avo.ramcache.config.IEntity;

import java.io.Serializable;

public enum EventType {

    SAVE() {
        @Override
        public void successHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onSaveSuccess(id, entity);
        }

        @Override
        public void errorHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onSaveError(id, entity, exception);
        }
    },

    UPDATE() {
        @Override
        public void successHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onUpdateSuccess(entity);
        }

        @Override
        public void errorHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onUpdateError(entity, exception);
        }
    },
    REMOVE() {
        @Override
        public void successHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onRemoveSuccess(id);
        }

        @Override
        public void errorHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {
            listener.onRemoveError(id, exception);
        }
    };

    public void successHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {

    }

    public void errorHandle(AbstractListener listener, boolean isSuccess, Serializable id, IEntity<?> entity, RuntimeException exception) {

    }
}
